import React, { Component } from 'react'
import { Card,Form,Input,Button,message } from 'antd'
import Loading from "../../components/Loading"
import { editArt } from "../../api" 
// 富文本
import wangEdit from 'wangeditor'


const layout = {
  labelCol: {
    span: 4,
  },
  wrapperCol: {
    span: 20,
  },
};

export default class ArtAdd extends Component {
  constructor(){
	  super()
	  
	  this.state = {
		  edit:null,
	  }
  }
  render() {
	
    return (
      <Card title="增加文章">
		
			<Form
			     {...layout}
			     name="basic"	
			     onFinish={ this.submit }
			   >
			     <Form.Item
			       label="标题"
			       name="title"
			       rules={[
			         {
			           required: true,
			           message: '请输入标题',
			         },
			       ]}
			     >
			       <Input/>
			     </Form.Item>
					
			     <Form.Item
			       label="作者"
			       name="author"
			       rules={[
			         {
			           required: true,
			           message: '请输入作者',
			         },
			       ]}
			     >
			       <Input />
			     </Form.Item>
				<Form.Item
				  label="描述"
				  name="desc"
				  >
				  <Input.TextArea/>
				</Form.Item>		  
				<Form.Item
				  label="内容"
				  name="desc"
				  >
				  <div id="txt"></div>
				</Form.Item>	
					
			     <Form.Item wrapperCol={ { offset:4,span:20 } }>
			       <Button type="primary" htmlType="submit">
			         提交
			       </Button>
			     </Form.Item>
			   </Form>
			
      </Card>
    )
  }
  componentDidMount(){
	  // 加载富文本
	  this.setState({
		  edit: new wangEdit("#txt")
	  },()=>{
		  this.state.edit.create()
	  })
  }
  
  submit = (params)=>{
	params.content = this.state.edit.txt.html()
	// 增加 文章接口 
	console.log(params);
  }
}
